package com.wow.wa.ui;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.wow.wa.ui.bean.UICategory;
import com.wow.wa.uicommon.R;

/**
 * 選擇視窗工具
 * 
 * @author ING
 * 
 */
public class CategoryItemDialog extends BaseDialog implements
		OnItemClickListener {

	private CategoryBtn btn;

	private ListView listView;
	private TextView titleView;
	private String titleName;

	private OnItemClickListener onItemClickListener = null;

	private List<UICategory> categorys;
	private UICategory selectBean = new UICategory();

	public CategoryItemDialog(String titleName, Context context, CategoryBtn btn) {
		super(titleName, context, btn.getCategorys());
		
		this.categorys = btn.getCategorys();
		this.btn = btn;

		listView = (ListView) this.getView().findViewWithTag("listView");
		titleView = (TextView) this.getView().findViewWithTag("title");

		this.getView().findViewById(R.id.title);
		this.onItemClickListener = this;
		listView.setOnItemClickListener(this.onItemClickListener);
	}

	@Override
	public String getTitle() {
		// TODO Auto-generated method stub
		return titleName;
	}

	public ListView getListView() {
		return listView;
	}

	public void setListView(ListView listView) {
		this.listView = listView;
	}

	public TextView getTitleView() {
		return titleView;
	}

	public void setTitleView(TextView titleView) {
		this.titleView = titleView;
	}

	public String getTitleName() {
		return titleName;
	}

	public void setTitleName(String titleName) {
		this.titleName = titleName;
	}

	public UICategory getSelectBean() {
		return selectBean;
	}

	public void setSelectBean(UICategory selectBean) {
		this.selectBean = selectBean;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		final UICategory category = categorys.get(arg2);
		this.selectBean.setCode(category.getCode());
		this.selectBean.setName(category.getName());
		this.btn.setCode(category.getCode());
		this.hide();
	}
}
